package com.badibadi.mail;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;

import com.badibadi.activity.BaseActivity;
import com.badibadi.activity.SelectPictsMail_Activity;
import com.badibadi.activity.ShowViewPagerActivity;
import com.badibadi.adapter.GridViewListAdapter;
import com.badibadi.adapter.Gridview3Adapter;
import com.badibadi.infos.Img;
import com.badibadi.infos.PayUserContactShow1Model;
import com.badibadi.infos.Results;
import com.badibadi.infos.UserInfoModel;
import com.badibadi.mytools.CalendarTools;
import com.badibadi.mytools.CommonUtils;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.DisplayUtil;
import com.badibadi.mytools.HtmlUtils;
import com.badibadi.mytools.ImageTools;
import com.badibadi.mytools.JSONUtils;
import com.badibadi.mytools.RegexUtils;
import com.badibadi.mytools.SinaExpressionTools;
import com.badibadi.mytools.Utils;
import com.badibadi.mytools.XUtils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.SinaExpressionActivity;
import com.badibadi.uniclubber.R.id;
import com.badibadi.uniclubber.R.layout;
import com.libjph.util.StringUtil;
import com.lidroid.xutils.util.LogUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.text.Editable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.StyleSpan;
import android.text.style.UnderlineSpan;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

//activity_mail_send activity_mail_send title time
public class Mail15_huifuActivity extends BaseActivity implements//activity_mail_send
		OnClickListener {
	// 匿名头像地址
	public String nimingHead = Constants.BadiDownImgUrl
			+ "/Public/Uploads/1.png" + Constants.appPhoto4img;
	private DisplayImageOptions options;
	private static final int BiaoQing = 8081;
	private ImageButton btn_textSize_Setting, btn_chuxi, btn_xiezhi,
			btn_xiahuaxian, btn_biaoqin, btn_paizhao, btn_movies;
	private Intent intent = null;
	private String[] ssp = { "5", "10", "15", "20", "25", "30", "35", "40",
			"45", "50" };
	protected EditText activity_mail_content, et_zhuzhi;
	protected TextView activity_mail_send, title_mail, clubAllPeople;
	protected ImageView activity_mail_titalimg;
	ListView lv;// 文字大小列表

	AlertDialog textdialog;
	/**
	 * 加粗 TextView tv = (TextView)findViewById(R.id.TextView01); TextPaint tp =
	 * tv.getPaint(); tp.setFakeBoldText(true);
	 * 
	 * login_registration.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //添加线
	 * //login_edit_username.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
	 * //删除线
	 */
	/**
	 * 是否是粗体
	 */
	private boolean isChuti = false;
	/**
	 * 是否是斜体
	 */
	private boolean isXieti = false;
	/**
	 * 是否有下划线
	 */
	private boolean hasXiahuaxian = false;

	// //用于判断是否需要咨询费（本activity的）
	// UserInfoModel userInfoModel;
	// String ask;//问方
	// private String answer;//答方
	// // private String answerName;
	// String is_anonymity;//是否匿名
	// private String is_fee;//是否需要咨询费
	CheckBox niming;

	PayUserContactShow1Model payUserContactShow1Model;
	// 下面的是照相机的
	private ArrayList<String> pathlist;
	private GridView picGridView;
	ArrayList<Img> imgs;
	Gridview3Adapter picGridView_adapter;
	ArrayList<String> htmp_list;
	public Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				Utils.ExitPrgress(Mail15_huifuActivity.this);
				try {
					Utils.showMessage(Mail15_huifuActivity.this, getResources()
							.getString(R.string.l_net_error));
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 2:
				Utils.ExitPrgress(Mail15_huifuActivity.this);
				try {
					Utils.showMessage(Mail15_huifuActivity.this, getResources()
							.getString(R.string.wx_send_success));
					finish();
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 3:
				Utils.ExitPrgress(Mail15_huifuActivity.this);
				try {
					Utils.showMessage(Mail15_huifuActivity.this, getResources()
							.getString(R.string.wx_send_false));
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 4:
				Utils.ExitPrgress(Mail15_huifuActivity.this);
				try {
					Utils.showMessage(Mail15_huifuActivity.this, getResources()
							.getString(R.string.wx_send_false));
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 5:// 答方的资料显示
				Utils.ExitPrgress(Mail15_huifuActivity.this);
				try {
					Utils.showMessage(Mail15_huifuActivity.this, getResources()
							.getString(R.string.l_xb12));

				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 2000:
				try {
					Utils.ExitPrgress(Mail15_huifuActivity.this);
					Utils.ExitProgress_hen(Mail15_huifuActivity.this);
					Utils.showMessage(Mail15_huifuActivity.this, getResources()
							.getString(R.string.l_xb18));
					String temp_path = msg.getData().getString("path");
					htmp_list = new ArrayList<String>();
					htmp_list = fenge(temp_path);

					for (int i = 0; i < htmp_list.size(); i++) {
						// activity_mail_content.setText(activity_mail_content
						// .getText().toString() + list3.get(i));
						// activity_mail_content.setSelection(activity_mail_content
						// .getText().toString().length());
						Img img = new Img();
						String cc = htmp_list.get(i).substring(10,
								htmp_list.get(i).length() - 4);
//						   
						img.setPath(cc);
						imgs.add(img);
					}
					picGridView_adapter.notifyDataSetChanged();

				} catch (Exception e) {
					// TODO: handle exception
				}

				break;

			default:
				break;
			}
		}

	};

	private ArrayList<String> fenge(String ds) {
		String dg[] = ds.split(",");
		ArrayList<String> list2 = new ArrayList<String>();
		if (dg != null) {
			for (int i = 0; i < dg.length; i++) {
				// <img
				// src='http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/7a/shenshou_thumb.gif'
				// />"
				if (dg[i].startsWith("http")) {
					list2.add("<img src='" + dg[i] + "' />");
				} else {
					list2.add("<img src='" + Constants.BadiDownImgUrl + dg[i]
							+ "' />");
				}
			}
		}
		return list2;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		goToTheTitle();
		setContentView(R.layout.huifuzhanneixin);
		options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.ic_stub)
				.showImageForEmptyUri(R.drawable.noimage)
				.showImageOnFail(R.drawable.noimage).cacheInMemory()
				.cacheOnDisc().displayer(new RoundedBitmapDisplayer(5)).build();
		int test = MailActivity.ALLMAIL;
		payUserContactShow1Model = (PayUserContactShow1Model) getIntent()
				.getSerializableExtra("payUserContactShow1Model");

		this.findViewById(R.id.return_btn).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Intent intent = new Intent(Mail15_huifuActivity.this,
								Mail8_14_15Activity.class);
						intent.putExtra("payUserContactShow1Model",
								payUserContactShow1Model);
						startActivity(intent);
						finish();
					}
				});
		// answer=getIntent().getStringExtra("answer");
		// userDataShow(answer);
		niming = (CheckBox) this.findViewById(R.id.check_niming);
		niming.setVisibility(View.GONE);
		LinearLayout niming2 = (LinearLayout) this.findViewById(R.id.niming);
		niming2.setVisibility(View.GONE);
		init();

	}

	public void init() {
		// TODO Auto-generated method stub
		// cid=getIntent().getStringExtra("cid");
		// admin_uid=getIntent().getStringExtra("admin_uid");
		// clubname=getIntent().getStringExtra("clubname");
		et_zhuzhi = (EditText) this.findViewById(R.id.et_zhuzhi);
		pathlist = new ArrayList<String>();
		btn_textSize_Setting = (ImageButton) this
				.findViewById(R.id.mail_textSize_Setting);
		btn_textSize_Setting.setOnClickListener(Mail15_huifuActivity.this);
		btn_chuxi = (ImageButton) this.findViewById(R.id.mail_chuxi);
		btn_chuxi.setOnClickListener(Mail15_huifuActivity.this);

		btn_xiezhi = (ImageButton) findViewById(R.id.mail_xie_zhi);
		btn_xiezhi.setOnClickListener(this);

		btn_xiahuaxian = (ImageButton) this.findViewById(R.id.mail_xiahuaxian);
		btn_xiahuaxian.setOnClickListener(this);
		activity_mail_content = (EditText) findViewById(R.id.activity_mail_content);
		activity_mail_titalimg = (ImageView) findViewById(R.id.activity_mail_titalimg);
		title_mail = (TextView) findViewById(R.id.title_mail);

		btn_paizhao = (ImageButton) findViewById(R.id.mail_paizhao);
		btn_paizhao.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(Mail15_huifuActivity.this,
						SelectPictsMail_Activity.class);
				intent.putExtra("panduan", "no_set");
				startActivityForResult(intent, 3);
			}
		});

		// 这一部分是拍照的
		picGridView = (GridView) this.findViewById(R.id.picture_GridView);
		picGridView.setHorizontalSpacing(DisplayUtil.dip2px(
				Mail15_huifuActivity.this, 5));
		picGridView.setVerticalSpacing(DisplayUtil.dip2px(
				Mail15_huifuActivity.this, 5));
		imgs = new ArrayList<Img>();

		picGridView_adapter = new Gridview3Adapter(Mail15_huifuActivity.this,
				imgs);
		picGridView.setAdapter(picGridView_adapter);
		picGridView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view,
					int position, long arg3) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(Mail15_huifuActivity.this,
						ShowViewPagerActivity.class);
				intent.putStringArrayListExtra("pic",
						(ArrayList<String>) picGridView_adapter.getSList());
				intent.putExtra("position", position);
				startActivity(intent);
			}
		});
		pathlist = new ArrayList<String>();
		//
		this.findViewById(R.id.mail_biaoqing).setOnClickListener(this);
		PeiZhi();
		DongTaiPeiZhi();
	}

	private void PeiZhi() {
		// TODO Auto-generated method stub
		// TextView content1=(TextView)this.findViewById(R.id.content1);
		// new HtmlUtils(Mail15_huifuActivity.this, content1,
		// payUserContactShow1Model.getZhannei_usercontact().get(0).getContents()).showTextView();

		btn_paizhao = (ImageButton) findViewById(R.id.mail_paizhao);
		btn_paizhao.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(Mail15_huifuActivity.this,
						SelectPictsMail_Activity.class);
				intent.putExtra("panduan", "no_set");
				startActivityForResult(intent, 3);
			}
		});

		ListView List_adapter = (ListView) this
				.findViewById(R.id.mail_nozixunfei_list);

		ListAdapter l_adapter = new ListAdapter();
		List_adapter.setAdapter(l_adapter);

		et_zhuzhi.setText(getResources().getString(R.string.wx_reply_kuohao)
				+ payUserContactShow1Model.getZhannei_usercontact().get(0)
						.getTitle());

		TextView shoujianfang = (TextView) this.findViewById(R.id.shoujianfang);

		if (payUserContactShow1Model.getReceiver().getNickName().equals("-1")) {
			shoujianfang.setText(getResources().getString(
					R.string.wx_Anonymous_user));
		} else {
			shoujianfang.setText(""
					+ payUserContactShow1Model.getReceiver().getNickName());
		}
		// 发送
		this.findViewById(R.id.activity_mail_send).setOnClickListener(
				new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						String content = activity_mail_content.getText()
								.toString().trim();
						if (!StringUtil.isNullOrEmpty(content)) {
							StringBuffer buff = new StringBuffer(content);
//							buff.append(content);
							if (imgs != null && !imgs.isEmpty()) {
								buff.append("<div>");
								for (int i = 0; i < imgs.size(); i++) {
									buff.append(Utils.toMailHtmL(imgs.get(i)
											.getPath()));
									//    
								}
								buff.append("<div style='clear:both;'></div></div>");
							}
							String content3 = buff.toString().trim();
							//    
							String content2 = SinaExpressionTools
									.replaceAllReplaceToPath(content3);
							content2 = content2.replaceAll("\\[", "");
							content2 = content2.replaceAll("\\]", "");
							//
							// String content3 = buff.toString();
							// String content2 = SinaExpressionTools
							// .replaceAllReplaceToPath(content3);

							answer(content2);
						} else {
							Utils.showMessage(Mail15_huifuActivity.this,
									getResources()
											.getString(R.string.wx_txt_81));
						}

					}
				});

	}

	protected void DongTaiPeiZhi() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.mail_xie_zhi:
			ChangeXieti();
			break;
		case R.id.mail_textSize_Setting:
			initDialog();
			break;
		case R.id.mail_chuxi:
			ChangeChuti();
			// if (isChuti) {
			// isChuti = false;
			// } else {
			// isChuti = true;
			// }
			break;
		case R.id.mail_xiahuaxian:
			ChangeXiaHuaXian();
			break;
		case R.id.mail_biaoqing:
			Intent intent = new Intent(Mail15_huifuActivity.this,
					SinaExpressionActivity.class);
			startActivityForResult(intent, BiaoQing);
			break;
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub

		if (keyCode == 4) {
			Intent intent = new Intent(Mail15_huifuActivity.this,
					Mail8_14_15Activity.class);
			intent.putExtra("payUserContactShow1Model",
					payUserContactShow1Model);
			startActivity(intent);
			finish();
		}

		return super.onKeyDown(keyCode, event);
	}

	@Override
	protected void onActivityResult(int arg0, int arg1, Intent arg2) {
		// TODO Auto-generated method stub
		if (arg0 == 3 && arg1 == SelectPictsMail_Activity.HUICHUAN_KEY_1) {
			if (arg2 != null) {
				pathlist = arg2.getStringArrayListExtra("files");
				// Utils.showMessage(Mail15_huifuActivity.this, getResources()
				// .getString(R.string.l_xb46));
				XUtils.UpImg_ceshi_douhaoXUtils(pathlist,
						Mail15_huifuActivity.this, handler);
			}
		}
		if (arg0 == BiaoQing
				&& arg1 == SinaExpressionActivity.ACTIVITY_BIAOQING) {
			if (arg2 != null) {
				// String con1 = activity_mail_content.getText().toString();
				// String con2 = arg2.getStringExtra("result");
				// activity_mail_content.setText(con1 + con2);
				// activity_mail_content.setSelection((con1 + con2).length());

				String content2 = arg2.getStringExtra("result");
				int index = activity_mail_content.getSelectionStart();
				Editable edit = activity_mail_content.getEditableText();
				edit.insert(index, content2);

			}

		}

		super.onActivityResult(arg0, arg1, arg2);
	}

	private void initDialog() {
		lv = new ListView(Mail15_huifuActivity.this);
		// lv.setChoiceMode(choiceMode);
		// ArrayAdapter<Integer> arr=new
		// ArrayAdapter<Integer>(getApplicationContext(), resource,
		// textViewResourceId, objects)
		final MySpSizeAdapter spAdapter = new MySpSizeAdapter();
		lv.setAdapter(spAdapter);
		lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int position, long arg3) {
				// TODO Auto-generated method stub
				setTextSize(Float.parseFloat((String) spAdapter
						.getItem(position)));
				if (textdialog != null) {
					textdialog.dismiss();
				}

			}
		});
		textdialog = new AlertDialog.Builder(Mail15_huifuActivity.this)
				.setTitle(getResources().getString(R.string.l_xb90))
				.setView(lv).show();
	}

	/**
	 * 设置字体大小
	 * 
	 * @param content
	 */
	private void setTextSize(Float content) {
		activity_mail_content.setTextSize(content);
	}

	/**
	 * 设置粗体和取消粗体
	 */
	private void ChangeChuti() {
		if (isChuti == false) {
			SpannableString msp = new SpannableString(activity_mail_content
					.getText().toString().trim());
			msp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0,
					msp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 粗体
			// activity_mail_content.
			// activity_mail_content.getPaint().setFakeBoldText(true);

			activity_mail_content.setText(msp);
			activity_mail_content.setSelection(msp.length());
			isChuti = true;
		} else {
			SpannableString msp = new SpannableString(activity_mail_content
					.getText().toString().trim());
			msp.setSpan(new StyleSpan(android.graphics.Typeface.NORMAL), 0,
					msp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 正常
			// activity_mail_content.
			// activity_mail_content.getPaint().setFakeBoldText(true);

			activity_mail_content.setText(msp);
			activity_mail_content.setSelection(msp.length());
			isChuti = false;
		}
		hasXiahuaxian = false;
		isXieti = false;
	}

	/**
	 * 设置字体下划线
	 */
	private void ChangeXiaHuaXian() {
		if (hasXiahuaxian == false) {
			SpannableString msp = new SpannableString(activity_mail_content
					.getText().toString().trim());
			msp.setSpan(new UnderlineSpan(), 0, msp.length(),
					Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
			// activity_mail_content.
			// activity_mail_content.getPaint().setFakeBoldText(true);

			activity_mail_content.setText(msp);
			activity_mail_content.setSelection(msp.length());
			hasXiahuaxian = true;
		} else {
			SpannableString msp = new SpannableString(activity_mail_content
					.getText().toString().trim());
			msp.setSpan(new StyleSpan(android.graphics.Typeface.NORMAL), 0,
					msp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 正常
			// activity_mail_content.getPaint().setFakeBoldText(false);
			activity_mail_content.setText(msp);
			activity_mail_content.setSelection(msp.length());
			hasXiahuaxian = false;
		}

		isChuti = false;
		isXieti = false;

	}

	/**
	 * 设置斜体和取消斜体
	 */
	private void ChangeXieti() {
		if (isXieti == false) {
			SpannableString msp = new SpannableString(activity_mail_content
					.getText().toString().trim());
			msp.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0,
					msp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 斜体
			// activity_mail_content.
			// activity_mail_content.getPaint().setFakeBoldText(true);

			activity_mail_content.setText(msp);
			activity_mail_content.setSelection(msp.length());
			isXieti = true;
		} else {
			SpannableString msp = new SpannableString(activity_mail_content
					.getText().toString().trim());
			msp.setSpan(new StyleSpan(android.graphics.Typeface.NORMAL), 0,
					msp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 正常
			// activity_mail_content.getPaint().setFakeBoldText(false);
			activity_mail_content.setText(msp);
			activity_mail_content.setSelection(msp.length());
			isXieti = false;
		}

		isChuti = false;
		hasXiahuaxian = false;
	}

	public class MySpSizeAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return ssp.length;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return ssp[position];
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub

			LayoutInflater inflater = LayoutInflater
					.from(Mail15_huifuActivity.this);
			convertView = inflater
					.inflate(R.layout.mail_sp_import_layout, null);

			TextView tv = (TextView) convertView
					.findViewById(R.id.mail_import_sp);
			tv.setText("" + ssp[position]);
			tv.setTextSize(Integer.parseInt(ssp[position]));
			// Typeface face=Typeface.createFromAsset(getAssets(),
			// "founts/cukaitijian.ttf");
			// tv.setTypeface(face);
			// Paint p=new Paint();
			// p.setTextSkewX(-1);
			return convertView;
		}
	}

	private class ListAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return payUserContactShow1Model.getZhannei_usercontact().size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {// title
			LayoutInflater inflater = LayoutInflater
					.from(Mail15_huifuActivity.this);
			View view = inflater.inflate(R.layout.mail_no_zhannei_item, null);
			TextView contents = (TextView) view
					.findViewById(R.id.zhannei_item_content);
//			   
			ImageView head = (ImageView) view.findViewById(R.id.head);
			TextView title = (TextView) view.findViewById(R.id.title);// 主旨
			TextView nickName = (TextView) view.findViewById(R.id.nickName);// 昵称
			GridView item_gridView = (GridView) view.findViewById(R.id.item);// 一个gridView
			TextView time = (TextView) view.findViewById(R.id.time);
			String type = "0";// 0.匿名 1，不匿名
			String is_sender = "1";// 1.问方，0答方
			String message_wenfang = "1";// 1.该条消息是问方发的，0答方发的
			if (payUserContactShow1Model.getIs_anonymity().equals("1")) {
				type = "0";
			} else {
				type = "1";
			}
			// 登录方是问方
			if (payUserContactShow1Model.getLoginUserRank().equals("asker")) {
				is_sender = "1";

			} else {
				is_sender = "0";
			}
			// 如果是该条消息的发送方
			// if
			// (payUserContactShow1Model.getZhannei_usercontact().get(position)
			// .getSender_rank().equals("asker")) {
			// message_wenfang = "1";
			// } else {
			// message_wenfang = "0";
			// }
			if (payUserContactShow1Model
					.getZhannei_usercontact()
					.get(position)
					.getSent_uid()
					.equals("" + payUserContactShow1Model.getReceiver().getId())) {
				message_wenfang = "0";
			} else {
				message_wenfang = "1";
			}

			// // 调用sender
			// if (type.equals("1")) {
			// ImageLoader.getInstance().displayImage(
			// Constants.BadiDownImgUrl + "/", head, options);
			// }

			// 获取所有的包含图片的<src= >类似的html语言
			List<String> list = null;
			if (payUserContactShow1Model.getZhannei_usercontact().get(position)
					.getContents() != null) {
				list = RegexUtils.getImgSrc(payUserContactShow1Model
						.getZhannei_usercontact().get(position).getContents());
				// for(int i=0;i<list.size();i++)
				// {
				// LogUtils.d("列表是：==》"+list.get(i).toString());
				// }

			}
			if (list != null && !list.isEmpty()) {
//				LogUtils.d("列表是：==》不是空");
				GridViewListAdapter adapter = new GridViewListAdapter(
						Mail15_huifuActivity.this, list);
				item_gridView.setAdapter(adapter);
				String aa = payUserContactShow1Model.getZhannei_usercontact()
						.get(position).getContents();

				// for(int i=0;i<list.size();i++)
				// {
				//
				// // <img src=' ' />
				// aa=aa.replace("<img src='"+list.get(i)+"' />","");
				// }
				List<String> listgroup = RegexUtils.getImgSrcGroup(aa);
				for (int i = 0; i < listgroup.size(); i++) {
					// <img src=' ' />
					if (listgroup.get(i)
							.indexOf(Constants.Fei_biaoqing_qianzui) != -1
							|| list.get(i).indexOf(
									Constants.Fei_biaoqing_qianzui2) != -1
							|| list.get(i).indexOf(
									Constants.Fei_biaoqing_qianzui3) != -1
							|| list.get(i).indexOf(
									Constants.Fei_biaoqing_qianzui4) != -1)
						aa = aa.replaceAll(listgroup.get(i), "");// ("<img src='"+list.get(i)+"' />","");
				}
				new HtmlUtils(Mail15_huifuActivity.this, contents, aa)
						.showTextView();
				// LogUtils.d("aa="+aa);
				// <img src=' '/ >

			} else if (list == null || list.isEmpty()) {
//				LogUtils.d("列表是：==》是空");
				new HtmlUtils(Mail15_huifuActivity.this, contents,
						payUserContactShow1Model.getZhannei_usercontact()
								.get(position).getContents()).showTextView();
			}

			// 获取所有的包含图片的<src= >类似的html语言 截止
			//
			// new HtmlUtils(Mail15_huifuActivity.this, contents,
			// payUserContactShow1Model.getZhannei_usercontact()
			// .get(position).getContents(),180).showTextView();
			title.setText(""
					+ getResources().getString(R.string.wx_zhuzhi_maohao)
					+ payUserContactShow1Model.getZhannei_usercontact()
							.get(position).getTitle());
			time.setText(""
					+ CalendarTools.getTimeChangeToString(
							Mail15_huifuActivity.this, payUserContactShow1Model
									.getZhannei_usercontact().get(position)
									.getTime()));
			// 如果问方匿名，该条消息是问方发的
			if (type.equals("0") && message_wenfang.equals("1")
					&& !is_sender.equals("1")) {
				nickName.setText(getResources().getString(
						R.string.wx_Anonymous_user));
				ImageLoader.getInstance().displayImage(nimingHead, head,
						options);
			} else// 该条消息是问方发的,问方没有匿名
			{
				nickName.setText(""
						+ payUserContactShow1Model.getSender().getNickName());
				ImageLoader.getInstance().displayImage(
						Constants.BadiDownImgUrl
								+ "/"
								+ payUserContactShow1Model.getSender()
										.getHead() + Constants.appPhoto4img,
						head, options);
			}
			// 如果是答方发的
			if (message_wenfang.equals("0")) {
				nickName.setText(""
						+ payUserContactShow1Model.getReceiver().getNickName());
				ImageLoader.getInstance().displayImage(
						Constants.BadiDownImgUrl
								+ "/"
								+ payUserContactShow1Model.getReceiver()
										.getHead() + Constants.appPhoto4img,
						head, options);
			}

			return view;
		}

	}

	/**
	 * 有咨询费，答方回复问方数据处理（第一次回复和第二次回复）---POST
	 * 
	 * @param $zhaneniId
	 *            站内信ID
	 * @param $uid
	 *            登录用户（答方）
	 * @param $reply_id
	 *            回复的是哪一条用户消息ID
	 * @param $title
	 *            回复的主旨
	 * @param $content
	 *            回复的内容
	 */
	public void answer(String content2) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("zhaneniId", payUserContactShow1Model.getZhannei_Id());
		map.put("uid", Utils.getUid(Mail15_huifuActivity.this));
		map.put("reply_id", payUserContactShow1Model.getContent_id());
		map.put("title", et_zhuzhi.getText().toString());
		map.put("content",
				SinaExpressionTools.replaceAllReplaceToPath(content2));
		CommonUtils.CommomPostfunction(Mail15_huifuActivity.this,
				Constants.BadiUrl_1 + "/" + "inform/answer", map, handler, 1,
				5, 2, 3);
	}

}
